package com.ogilvy.audi.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ogilvy.audi.bean.Acmnt;
import com.ogilvy.audi.bean.Album;
import com.ogilvy.audi.bean.Circle;
import com.ogilvy.audi.service.AcmntService;
import com.ogilvy.audi.service.AlbumService;
import com.ogilvy.audi.service.CircleService;
import com.ogilvy.audi.util.MethodTools;
import com.ogilvy.frame.action.BaseAction;
@SuppressWarnings("serial")
@Scope("prototype")
@Controller("auti.action.AlbumAction")
public class AlbumAction extends BaseAction {
	@Autowired
	protected AlbumService albumService;
	@Autowired
	protected CircleService circleService;
	@Autowired
	protected AcmntService acmntService;
	public String albumId;
	public String pageNum;
	public String circleId;
	
	public List<Album> albumList; //相册 列表 
	public List<Circle> circleList;//圈子列表
	public List<Acmnt> acmntList;//评论列表
	public List<String> picList;//相片列表 
	public Album album;

	public String list() {
		if(MethodTools.nullStr(pageNum).equals("")){
			pageNum = "1";
		}
		Map<String,Object> condition = new HashMap<String,Object>();
		if(MethodTools.nullStr(circleId).equals("")){
			condition.put("circleId", circleId);
		}
		albumList = albumService.query(Integer.parseInt(pageNum), 10, condition);
		
		condition = new HashMap<String,Object>();
		if(MethodTools.nullStr(albumId).equals("")){
			condition.put("albumId", albumId);
		}
		acmntList = acmntService.query(Integer.parseInt(pageNum), 10, condition);
		
		return "list";
	}
	//http://localhost:8080/AudiProject/audi/album_detail.action?albumId=1
	public String detail() {
		if(MethodTools.nullStr(pageNum).equals("")){
			pageNum = "1";
		}
		Map<String,Object> condition = new HashMap<String,Object>();
		if(MethodTools.nullStr(circleId).equals("")){
			condition.put("circleId", circleId);
		}
		
		album = albumService.get(Integer.parseInt(albumId));
		//返回相片list
		picList = albumService.getPicList(Integer.parseInt(albumId));
		//albumList = albumService.query(Integer.parseInt(pageNum), 10, conition);
		
		condition = new HashMap<String,Object>();
		if(MethodTools.nullStr(albumId).equals("")){
			condition.put("albumId", albumId);
		}
		acmntList = acmntService.query(Integer.parseInt(pageNum), 10, condition);
		System.out.println("deubg");
		return "list";
	}

	public String add() {
		Album album = new Album();
		albumService.add(album);
		return null;
	}

	public String modify() {
		return null;
	}

	public String del() {
		albumService.del(Integer.parseInt(albumId));
		return null;

	}
}






























